/**
find -n[line num] -x[pattern]
find -nx [pattern]
*/
#include<stdio.h>
#include<string.h>

#define MAX_LINE 200

int mygetline(char* line,int maxline);
int mystrcmp(char* s,char* t);

main(int argc,char** argv){
	char    line[MAX_LINE];
	char*   pattern;
	int     shownum = 0;
	int     match = 0;
	int     find = 0;
	char    c;
	int     linenum = 0;
	while(--argc > 0 && (*++argv)[0] == '-')
	   while(c = *++argv[0]){
	      switch(c){
	         case  'n':
		     shownum = 1;
		     break;
                         case 'x':
                             match = 1;
                             break;	 
                         default:
                             argc = 0;
                             find = -1;	
                             break;
                      }
                   }

	if(argc !=1)
  	   printf("Usage: find -x -n [pattern]\n");
	else
	   while(mygetline(line,MAX_LINE) > 0){
	      linenum ++;
	      if(match && mystrcmp(line,*argv)==0){
	         if(shownum)
		    printf("%d",linenum);
		 printf("%s",line);
		 find++;
              }
	   }
	return 0;
}

int mygetline(char line[],int maxline)
{
	int c,i;
	for(i=0;i<maxline-1 && (c=getchar()) != EOF && c!='\n';i++){
		line[i] = c;
	}
	if(c == '\n'){
		line[i] = '\0';
		//i++;
	}
	line[i] = '\0';
	return i;
}

int mystrcmp(char* s,char* t)
{
	char c1,c2;
	for(;*s == *t;s++,t++){
		c1 = *s;
		c2  = *t; 
		if(*s == '\0')
			return 0;
	}
	return *s - *t;
}
